%Data for Case Study 7: The Singular Value Decomposition and Image
%Processing

ex = input('Examples (0) or Exercise number (1, 2)? ');
       
if ex==0

B = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;...
   0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,0;...
   0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,1, 1, 1, 0, 0, 0, 0, 0;...
   0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0;...
   0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0;...
   0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0;...
   0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1;...
   0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1;...
   0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1;...
   0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0;...
   1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0;...
   1, 1, 0, 0,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, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0;...
   0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0; ...
   0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0; ...
   0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0;...
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0];


[U,S,V]=svd(B);
sigma1 = svds(B, 1); u1 = U( :, 1 ); v1 = V( :, 1); B1 = u1*diag(sigma1)*v1'; 
sigma2 = svds(B, 2); u2 = U( :, [1 2]); v2 = V( :, [1 2]); B2 = u2*diag(sigma2)*v2';
sigma3 = svds(B, 3); u3 = U( :, [1 2 3]); v3 = V( :, [1 2 3]); B3 = u3*diag(sigma3)*v3'; 
sigma4 = svds(B, 4); u4 = U( :, [1 2 3 4]); v4 = V( :, [1 2 3 4]); B4 = u4*diag(sigma4)*v4'; 
sigma5 = svds(B, 5); u5 = U( :, [1:5]); v5 = V( :, [1:5]); B5 = u5*diag(sigma5)*v5';
sigma10 = svds(B, 10); u10 = U( :, [1:10]); v10 = V( :, [1:10]); B10 = u10*diag(sigma10)*v10'; 
disp('Type B, B1, B2, B3, B4, B5, or B10 for the matrices in the example')
disp('Type "contourf(B), colormap(gray)" OR "contourf(B1), colormap(gray)" etc. for the the contour map.')

elseif ex==1
   
   [I,J]=meshgrid(-6:1:6);  S=sin((I/3).^2+(J/3).^2)
elseif ex==2
   C = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
   0, 1, 1, 0, 0,  0, 1, 1, 0, 0, 1, 1, 1, 1, 0;
   0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0;
   0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0;
   0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0; 
   0, 1,1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0; 
   0, 1, 1, 0, 0, 0, 1, 1,0, 0, 0, 1, 1, 0, 0;
   0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1,0, 0;
   0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0; 
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] 
 
else
   disp('No data for this exercise for Case Study 7.') 
end






